﻿Imports System.IO

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim instance = New myfile
        Dim source As String = RichTextBox1.Text
        Dim currentTime As DateTime = Now
        Dim path As String = Application.StartupPath & "/999.txt"
        instance.writeToFile(source, path)
    End Sub
    Private Sub button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim currentTime As DateTime = Now
        RichTextBox1.Text = currentTime

    End Sub
    Private Sub button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        RichTextBox1.Text = ""

    End Sub
    Private Sub button4_Click(sender As Object, e As EventArgs) Handles Button4.Click

        RichTextBox2.Text = ""

    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Dim instance = New myfile
        Dim sourcePath = TextBox2.Text
        If sourcePath.Length <> 0 Then
            Dim sourceContent = instance.ReadFromFile(sourcePath)
            RichTextBox2.Text = sourceContent
        Else
            MsgBox("路径不能空")
            Me.StartPosition = FormStartPosition.CenterParent
        End If


    End Sub

    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        SaveFileDialog1.Filter = "文本文件|*.txt"
        If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
            TextBox1.Text = SaveFileDialog1.FileName
        End If

    End Sub

    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        OpenFileDialog1.Filter = "文本文件|*.txt"
        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            TextBox2.Text = OpenFileDialog1.FileName
        End If
    End Sub
End Class
Public Class myfile
    Public Sub writeToFile(con As String, path As String)
        Dim writer = New StreamWriter(path)
        writer.WriteLine(con)
        writer.Close()
    End Sub

    Public Function ReadFromFile(path As String) As String
        Dim reader = New StreamReader(path)
        Dim con = reader.ReadLine
        Return con
    End Function
End Class